<template>
    <div class="main">
        <div style="width: 100%;height: 40px;background-color: #fff;margin-bottom: 20px;padding: 10px;">当前模块:<span
                style="font-weight: bold;">查询本校区当前学期的学生信息并进行管理(学生成绩统计属性管理) </span> </div>
        <div class="main-body">

            <div class="main-header float-left">

                <el-form :inline="true" :model="formInline" class="demo-form-inline" size="mini">

                    <el-form-item label="筛选条件：">
                        <el-select v-model="formInline.nj" placeholder="请选择" clearable @change="NjChanges">
                            <el-option v-for="(item, index) in ddl_bb_list" :key="index" :label="item.mc"
                                :value="item.dm">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="">
                        <el-select v-model="formInline.bj" placeholder="请选择" clearable>
                            <el-option v-for="(item, index) in bjList" :key="index" :label="item.BJ + '班'"
                                :value="item.BJ">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="">
                        <el-input v-model="formInline.xm" placeholder="学生姓名" clearable>
                        </el-input>
                    </el-form-item>
                    <!-- /bjList -->
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit" icon="el-icon-search">查询</el-button>
                        <el-button type="primary" icon="el-icon-upload" @click="importStu">下载参考名单</el-button>
                    </el-form-item>
                </el-form>

            </div>
            <div class="main-center float-left">
                <el-table :data="tableData" height="650" style="width: 100%;margin-top: 6px;"
                    :header-cell-style="{ background: '#fafafa', color: '#000000e0', fontWeight: 600 }">
                    <el-table-column type="index" label="序号"></el-table-column>
                    <el-table-column prop="NJMC" label="年级"></el-table-column>
                    <el-table-column prop="BJ" label="班级"></el-table-column>
                    <el-table-column prop="XH" label="学号"></el-table-column>
                    <el-table-column prop="XM" label="姓名"></el-table-column>
                    <el-table-column prop="XSLB" label="学生类别"></el-table-column>
                    <el-table-column prop="KSSX" label="学生来源"></el-table-column>
                    <el-table-column prop="CKXZ" label="中高考属性"></el-table-column>
                    <el-table-column prop="DQZT" label="当前状态"></el-table-column>
                    <el-table-column label="管理操作" width="200">
                        <template slot-scope="scope" style="z-index: -9999;">
                            <el-button @click="handleView(scope.row)" type="text" size="small" style="color: #ff4d4f;"
                                icon="el-icon-view">详情</el-button>
                            <el-button @click="handleEdit(scope.row)" type="text" size="small" style="color: #ff4d4f;"
                                icon="el-icon-edit">编辑</el-button>

                        </template>
                    </el-table-column>
                </el-table>

                <div class="footer-pagination">
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="formInline.currentPage" :page-sizes="[10, 20, 30, 50, 100, 200, 300, 500]"
                        :page-size="formInline.limit" layout="total, sizes, prev, pager, next, jumper"
                        :total="formInline.total">
                    </el-pagination>
                </div>
            </div>



            <el-dialog title="学生信息查看操作窗口" :visible.sync="dialogDetails" width="40%" :close-on-click-modal="false">
                <div>
                    <div style="width:100%;">
                        <table border='0' cellspacing="0" cellpadding="0"
                            style="border-collapse:collapse;border-style:none;font-family:宋体;font-size:13px; width:100%; ">
                            <tr>
                                <td class="td1" style=" width:100px;">
                                    身份证件类型
                                </td>
                                <td class="td1" style=" width:200px;">
                                    <span v-text="studentInfo.SFZJLX"></span>
                                </td>
                                <td class="td1" style=" width:100px;">
                                    身份证件号码
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.SFZJH"></span>
                                </td>

                            </tr>
                            <tr>
                                <td class="td1">
                                    <span style="color: red;">*</span>姓名
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.XM"></span>
                                </td>
                                <td class="td1">
                                    性别
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.XBM"></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="td1">
                                    学生类别
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.XSLB"></span>
                                </td>
                                <td class="td1">
                                    户籍省份
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.HKSF"></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="td1">
                                    出生年月
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.CSRQ"></span>
                                </td>
                                <td class="td1">
                                    本市中高考
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.xsly"></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="td1">
                                    就读学校
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.XQJC"></span>
                                </td>
                                <td class="td1">
                                    就读校区
                                </td>
                                <td colspan="2" class="td1">
                                    <span v-text="studentInfo.XJXQJC"></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="td1">
                                    就读年级
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.NJ"></span>
                                </td>
                                <td class="td1">
                                    编入行政班
                                </td>
                                <td colspan="2" class="td1">
                                    <span v-text="studentInfo.BJ"></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="td1">
                                    现居住地址
                                </td>
                                <td colspan="4" class="td1">
                                    <span v-text="studentInfo.dizhi"></span>

                                </td>
                            </tr>
                            <tr>
                                <td class="td1">
                                    学生考号
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.XH"></span>
                                </td>
                                <td class="td1">
                                    当前状态
                                </td>
                                <td class="td1">
                                    <span v-text="studentInfo.DQZT"></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="td1">
                                    联系电话
                                </td>
                                <td colspan="2" class="td1">
                                    <span v-text="studentInfo.LXDH"></span>
                                </td>
                            </tr>

                        </table>
                    </div>
                </div>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogDetails = false">取 消</el-button>

                </span>
            </el-dialog>


            <el-dialog title="学生参加考试属性修改窗口" :visible.sync="dialogDetails2" width="40%" :close-on-click-modal="false">
                <div>
                    <div style="width:100%;">
                        <table border='0' cellspacing="0" cellpadding="0"
                            style="border-collapse:collapse;border-style:none;font-family:宋体;font-size:13px; width:100%; ">
                            <tr>
                                <td class="td1" style=" width:100px;">
                                    学生姓名
                                </td>
                                <td class="td1" style=" width:200px;">
                                    <span v-text="stuInfo.XM"></span>
                                </td>
                                <td class="td1" style=" width:100px;">
                                    就读学校
                                </td>
                                <td class="td1">
                                    <span>{{ formatXq(stuInfo.XQDM) }}</span>
                                </td>

                            </tr>
                            <tr>
                                <td class="td1">
                                    就读年级
                                </td>
                                <td class="td1">
                                    <span>{{ (stuInfo.NJMC) }}</span>
                                </td>
                                <td class="td1">
                                    行政班级
                                </td>
                                <td class="td1">
                                    <span v-text="stuInfo.BJ"></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="td1">
                                    学号
                                </td>
                                <td class="td1">
                                    <span v-text="stuInfo.XH"></span>
                                </td>
                                <td class="td1">
                                    学生类别
                                </td>
                                <td class="td1">
                                    <span v-text="stuInfo.XSLB"></span>
                                </td>
                            </tr>
                            <tr>
                                <td class="td1">
                                    学生来源
                                </td>
                                <td class="td1">
                                    <el-radio v-model="radio" label="1">本市考生</el-radio>
                                    <el-radio v-model="radio" label="0">外地考生</el-radio>
                                    <!-- <span v-text="stuInfo.xsly"></span> -->
                                </td>
                                <td class="td1">
                                    中高考属性
                                </td>
                                <td class="td1">
                                    <el-radio v-model="radio2" label="1">参加</el-radio>
                                    <el-radio v-model="radio2" label="0">不参加</el-radio>
                                    <!-- <span v-text="stuInfo.zgksx"></span> -->
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogDetails2 = false">取 消</el-button>
                    <el-button @click="editstuinfo" type="primary">提 交</el-button>
                </span>
            </el-dialog>
        </div>
    </div>
</template>
<script>
import httplogin from "../../api/login";
export default {
    name: 'Social',
    data() {
        return {
            printOption: {
                id: 'nbprint', // 打印元素的id 不需要携带#号
                popTitle: '教职工基本信息登记表' // 页眉标题 默认浏览器标题 空字符串时显示undefined 使用html语言
            },
            ruleForm: {
                id: "",
                xk: '',
                bj: "",
                type: [],
                type2: [],

                xh: ""

            },
            radio: "",
            radio2: "",
            bj: "",
            tableData: [],
            tableData2: [],
            formInline: {
                xq: "",
                nj: '',
                xm: '',
                bj: "",
                ddl_xz: '',
                ddl_jdfs: '',
                currentPage: 1,
                limit: 10,
                total: 0
            },
            formInline2: {
                xq: "",
                nj: '',
                xm: '',
                ddl_xz: '',
                ddl_jdfs: '',
                currentPage: 1,
                limit: 10,
                total: 0
            },
            ddl_lb_list: [

            ],//类别 options
            ddl_bb_list: [],//办别 options
            ddl_xz_list: [
                {
                    value: '全部',
                    label: '全部'
                },
                {
                    value: '普通',
                    label: '普通'
                },
                {
                    value: '工读',
                    label: '工读'
                },
                {
                    value: '特教',
                    label: '特教'
                },
            ],//性质 options
            ddl_jdfs_list: [
                {
                    value: '全部',
                    label: '全部'
                },
                {
                    value: '走读',
                    label: '走读'
                },
                {
                    value: '寄宿',
                    label: '寄宿'
                },
            ],//就读方式 options
            dialogDetails: false,
            dialogDetails2: false,
            JiaoZhiGongInfo: {},
            schoolList: [],
            xklist: [],
            title: "",
            TeacherId: "",
            bjList: [],
            url: "",
            stuInfo: {},
            studentInfo: {}
        }
    },
    mounted() {
        this.getGradeway();
        this.getTeacherSubjectway()
        this.getUserPermissionInfofun()
    },
    methods: {
        async getUserPermissionInfofun() {
            let res = await httplogin.getUserPermissionInfo();
            if (res.data.code == 200) {

                this.schoolList = res.data.data.UserPermission

            }
        },
        formatXq(val) {
            console.log(val)
            if (!val) {
                return
            }
            var obj = this.schoolList.filter((e) => {
                return e.NEW_XQDM == val
            })
            return obj[0].XQJC
        },
        async editstuinfo() {
            let data = {
                stuId: this.stuInfo.STU_ID,
                bsks: this.radio,
                ckxz: this.radio2
            }
            var res = await httplogin.updateXzFb(data);
            if (res.data.code == 200) {
                this.$message({
                    type: 'success',
                    message: res.data.msg
                });
                this.getTeacherSubjectway()

                this.dialogDetails2 = false
            }
        },
        handleView(row) {
            this.studentInfo.xsly = row.xsly
            this.selectHistoryStuInfoway(row.STU_ID);
            this.dialogDetails = true
        },

        async selectHistoryStuInfoway(val) {
            let data = {
                stuId: val
            }
            var res = await httplogin.selectHistoryStuInfo(data);
            if (res.data.code == 200) {
                this.studentInfo = res.data.data.list
            }
        },

        async getGradeway() {
            let res = await httplogin.getGrade();
            if (res.data.code == 200) {
                this.ddl_bb_list = res.data.data.list
                this.formInline.nj = this.ddl_bb_list[0].dm
                this.selectSchoolClassListway(this.formInline.nj)

            }
        },
        NjChanges(val) {
            this.selectSchoolClassListway(val)
        },
        async selectSchoolClassListway(val, row) {
            var data = {
                nj: val,
                xqdm: localStorage.getItem("selXQDM")
            }
            var res = await httplogin.selectSchoolClassList(data);

            if (res.data.code == 200) {
                this.bjList = res.data.data.list;
                if (row) {
                    this.ruleForm.bj = row.BJ
                }


            }
        },
        async submitForm() {

            var data = {
                stuId: this.stuInfo.STU_ID,
                xh: this.ruleForm.XH,
                bj: this.ruleForm.bj
            }
            var res = await httplogin.updateXzFb(data)
            if (res.data.code == 200) {
                this.$message({
                    type: 'success',
                    message: res.data.msg
                });
                this.getTeacherSubjectway()
                this.getTeacherSubjectway2()
                this.dialogDetails = false

            }
        },

        async getAllDistListway() {
            var res = await httplogin.getAllDistList();
            if (res.data.code == 200) {
                this.xklist = res.data.data.data.dm_xk
                this.ruleForm.xk = this.xklist[0].DM

            }
        },
        async getTeacherSubjectway() {
            let data = {
                xqdm: localStorage.getItem("selXQDM"),
                page: this.formInline.currentPage,
                size: this.formInline.limit,
                nj: this.formInline.nj,
                bj: this.formInline.bj,
                xm: this.formInline.xm
            }
            let res = await httplogin.selectKsStudent(data);
            if (res.data.code == 200) {
                this.tableData = res.data.data.list;
                this.formInline.total = res.data.data.total
            }
        },





        //getGrade

        getNowTimeDate() {
            const now = new Date();
            const year = now.getFullYear();
            const month = ('0' + (now.getMonth() + 1)).slice(-2);
            const day = ('0' + now.getDate()).slice(-2);
            // const hours = ('0' + now.getHours()).slice(-2);
            // const minutes = ('0' + now.getMinutes()).slice(-2);
            // const seconds = ('0' + now.getSeconds()).slice(-2);
            const formattedTime = year + "年" + month + "月" + day + "日"
            return formattedTime
        },
        sortPingyinfun(list) {
            list.sort((a, b) => a.XQJC.localeCompare(b.XQJC))
            return list
        },
        //点击查看详情 open 弹框
        handleClick(row) {
            this.getOnGuardFacultyInfoway(row)
            this.dialogDetails = true
        },
        async getOnGuardFacultyInfoway(val) {
            var data = {
                jzgId: val.TeacherID
            }
            var res = await httplogin.getOnGuardFacultyInfo(data)
            if (res.data.code == 200) {
                this.JiaoZhiGongInfo = res.data.data.jzgInfo

            }
        },
        handleEdit(row) {
            this.stuInfo = row
            if (this.stuInfo.KSSX == "本市考生") {
                this.radio = "1"
            } else {
                this.radio = "0"
            }
            if (this.stuInfo.CKXZ == "参加中高考") {
                this.radio2 = "1"
            } else {
                this.radio2 = "0"

            }
            this.dialogDetails2 = true
        },
        //close 弹框
        handleClose() {
            this.dialogDetails = false
        },
        onSubmit() {
            this.getTeacherSubjectway()
            // console.log(this.formInline);
        },
        handleSizeChange(val) {
            this.formInline.limit = val
            this.getTeacherSubjectway()
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.formInline.currentPage = val
            this.getTeacherSubjectway()
            console.log(`当前页: ${val}`);
        },
        handleSizeChange2(val) {
            this.formInline2.limit = val
            this.getTeacherSubjectway2()
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange2(val) {
            this.formInline2.currentPage = val
            this.getTeacherSubjectway2()
            console.log(`当前页: ${val}`);
        },
        async importStu() {
            var data={
                xqdm: localStorage.getItem("selXQDM")
            }
            var res = await httplogin.exportStuKsInfo(data)
            if (res.data.code == 200) {
                this.downloadUrl(res.data.data.url)

            }
        },
        downloadUrl(url) {

            // console.log(url);
            let link = document.createElement("a");
            //创建一个a标签
            link.style.display = "none";
            //将a标签隐藏
            link.href = url;
            //给a标签添加下载链接  "域名+接口"  safe是一个动态的域名  后面的接口替换成你自己的下载接口
            link.setAttribute("download", name);
            // 此处注意，要给a标签添加一个download属性，属性值就是文件名称 否则下载出来的文件是没有属性的，空白白
            document.body.appendChild(link);
            //将上面创建的a标签加入到body的尾部
            link.click();
            //执行a标签
        },

    }
}
</script>

<style scoped>
.main {
    width: 100%;
    float: left;
    height: auto;
    box-sizing: border-box;
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #f6f6f6;
    overflow-x: auto;
    overflow-y: auto;
}

.main-body {
    width: 100%;
    height: auto;
    float: left;
    background-color: #fff;
    box-sizing: border-box;
    padding: 18px;
    border-radius: 12px;
}

.float-left {
    width: 100%;
    height: auto;
    float: left;
}

.main-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.d-flex {
    display: flex;
    align-items: center;
}

.mr-24 {
    margin-right: 24px;
}

.fontcolor {
    color: rgba(0, 0, 0, 0.88);
    word-break: break-word;
    line-height: 1.5714285714285714;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
    font-size: 14px;
    box-sizing: border-box;
}

.footer-pagination {
    padding: 10px 0 0 0;
    text-align: right;
}

.font-all {
    color: rgba(0, 0, 0, 0.88);
    font-size: 14px;
    line-height: 1.5714285714285714;
    list-style: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
    scrollbar-color: rgba(0, 0, 0, 0.25) rgba(5, 5, 5, 0.06);
}
</style>

<style scoped>
.td1 {
    border: 1px solid #8c8c8c;
    height: 40px;
    text-align: center;
    line-height: 40px;
    color: #3c3c3c;
    padding: 3px;
    /* width: 40%; */
}

.inputbox {
    text-align: center;
    line-height: 25px;
    border: 1px solid #b3b3b3;
    font-size: 13px;
    height: 25px;
    width: 96%;
}

.rblList td {
    font-size: 13px;
    color: #3c3c3c;
    border-style: none;
    text-align: left;
    height: 30px;
    line-height: 30px;
}

::v-deep .el-dialog {
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    position: absolute;
    top: 44%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: calc(100% - 30px);
    max-width: calc(100% - 30px);
}

::v-deep .el-dialog .el-dialog__body {
    flex: 1;
    overflow: auto;
}

::v-deep .el-dialog__header {
    background-color: #ff4d4f !important;

}

::v-deep .el-dialog__title {
    line-height: 24px;
    font-size: 20px;
    color: #fff !important;
    /* font-weight: 600; */
}
</style>